/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RemoveExercicio.java
 *
 * Created on 13/07/2009, 13:18:54
 */
package interfaceGraficaUsuario;

import controle.Sistema;
import disciplina.Exercicio;
import java.awt.Color;

/**
 *
 * @author João Paulo
 */
public class RemoveExercicio extends javax.swing.JFrame {

    /** Creates new form RemoveExercicio */
    public RemoveExercicio() {
        initComponents();
        labelMensagem.setVisible(false);
        setTitle("Remover Exercício");
        campoID.setText("0");
        painelExibir.setText(Sistema.listaDeExercicios());
        painelExibir.setEnabled(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        painelExibir = new javax.swing.JTextPane();
        labelID = new javax.swing.JLabel();
        campoID = new javax.swing.JTextField();
        botaoExibir = new javax.swing.JButton();
        botaoSair = new javax.swing.JButton();
        botaoListar = new javax.swing.JButton();
        botaoRemover = new javax.swing.JButton();
        labelMensagem = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        painelExibir.setBackground(new java.awt.Color(240, 240, 240));
        painelExibir.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        painelExibir.setSelectionColor(new java.awt.Color(0, 0, 0));
        jScrollPane1.setViewportView(painelExibir);

        labelID.setText("ID do Exercício:");

        botaoExibir.setText("Exibir");
        botaoExibir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoExibirActionPerformed(evt);
            }
        });

        botaoSair.setText("Sair");
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSairActionPerformed(evt);
            }
        });

        botaoListar.setText("Listar");
        botaoListar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoListarActionPerformed(evt);
            }
        });

        botaoRemover.setText("Remover");
        botaoRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoverActionPerformed(evt);
            }
        });

        labelMensagem.setText("Mensagem");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 672, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(labelID)
                                .addGap(18, 18, 18)
                                .addComponent(campoID, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(botaoListar))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botaoExibir)
                                .addGap(18, 18, 18)
                                .addComponent(botaoRemover)
                                .addGap(18, 18, 18)
                                .addComponent(botaoSair))
                            .addComponent(labelMensagem, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE))))
                .addGap(48, 48, 48))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelID)
                    .addComponent(campoID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoExibir)
                    .addComponent(botaoRemover)
                    .addComponent(botaoSair))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoListar)
                    .addComponent(labelMensagem))
                .addGap(1, 1, 1)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoExibirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoExibirActionPerformed
        Exercicio exercicio = procuraExercicio(Integer.parseInt(campoID.getText()));
        painelExibir.setText(Sistema.exibirQuestoes(exercicio));
}//GEN-LAST:event_botaoExibirActionPerformed

    private void botaoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSairActionPerformed
        dispose();
}//GEN-LAST:event_botaoSairActionPerformed

    private void botaoListarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoListarActionPerformed
        painelExibir.setText(Sistema.listaDeExercicios());
}//GEN-LAST:event_botaoListarActionPerformed

    private void botaoRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRemoverActionPerformed
        if (Sistema.removerExercicio(Integer.parseInt(campoID.getText()))) {
            labelMensagem.setText("Exercício removido");
            labelMensagem.setForeground(Color.BLUE);
            labelMensagem.setVisible(true);
        } else {
            labelMensagem.setText("Não foi possível remover o exercício");
            labelMensagem.setForeground(Color.RED);
            labelMensagem.setVisible(true);
        }
    }//GEN-LAST:event_botaoRemoverActionPerformed
    private Exercicio procuraExercicio(int id) {
        return Sistema.getExercicio(id);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RemoveExercicio().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoExibir;
    private javax.swing.JButton botaoListar;
    private javax.swing.JButton botaoRemover;
    private javax.swing.JButton botaoSair;
    private javax.swing.JTextField campoID;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelID;
    private javax.swing.JLabel labelMensagem;
    private javax.swing.JTextPane painelExibir;
    // End of variables declaration//GEN-END:variables
}
